<template>
    <div style="padding: 10px;">
        <div style="margin: 10px;">
            <el-button type="primary" @click="addDialogVisible = true">新建表单</el-button>
            <el-input v-model="inputZ" placeholder="请输入表单名称" style="width: 300px;margin-left: 40px;"></el-input>
            <el-button type="primary" @click="handleQuery" style="margin-left: 15px;">查询</el-button>
            <el-button type="primary" @click="chongzhi">重置</el-button>
        </div>
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="mingcheng" label="表单名称" width="180">
            </el-table-column>
            <el-table-column prop="shuliang" label="字段数量" width="180">
            </el-table-column>
            <el-table-column prop="bitianxiang" label="必填项">
            </el-table-column>
            <el-table-column label="是否启用">
                <template slot-scope="scope">
                    <el-switch v-model="scope.row.enabled" active-color="#13ce66" inactive-color="#ff4949"
                        :disabled="scope.row.disabled">
                        <template #open>
                            <span>启用</span>
                        </template>
                        <template #close>
                            <span>停用</span>
                        </template>
                    </el-switch>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button type="text" size="small" style="margin-left:5px;"
                        @click="Edit(scope.row)">&nbsp;修改</el-button>
                    <el-button type="text" size="small" style="margin-left:5px;"
                        @click="Del(scope.row)">&nbsp;删除</el-button>
                </template>
            </el-table-column>
        </el-table>


        <div class="block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="currentPage4" :page-sizes="[1, 2, 3, 4, 5]" :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>

        <!-- 添加弹出框 -->
        <div>
            <el-dialog :visible.sync="addDialogVisible" title="新建表单" width="30%" :style="{ 'height': '90%' }">
                <el-form>
                    <el-form-item label="表单名称">
                        <el-input v-model="input" placeholder="请输入内容" style="width: 300px;"></el-input>
                    </el-form-item>
                    <el-form-item label="字段数量">
                        <el-input v-model="input2" placeholder="请输入内容" style="width: 300px;"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer" style="text-align: center;">
                    <el-button @click="addDialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="handleAdd">添加</el-button>
                </div>
            </el-dialog>
        </div>


    </div>
</template>

<script>
export default {
    data() {
        return {
            inputZ: '',
            input: '',
            input2: '',
            addDialogVisible: false,
            total: 0,
            value1: true,
            options: [{
                value: '选项1',
                label: '全部'
            }, {
                value: '选项2',
                label: '服务器'
            }, {
                value: '选项3',
                label: '储存'
            }, {
                value: '选项4',
                label: '网络设备'
            }, {
                value: '选项5',
                label: '机房环境'
            }, {
                value: '选项6',
                label: '桌面PC'
            }, {
                value: '选项7',
                label: '外设'
            },
            ],
            value: '',
            tableData: [
            ],
            pageSize: 5,
            currentPage4: 1,


        }
    },
    methods: {

        //渲染
        Redom() {
            this.$axios({
                url: `wuJiFour?_page=${this.currentPage}&_limit=${this.pageSize}`,
                params: {
                    mingcheng_like: `${this.inputZ}`
                }
            }).then(({ data }) => {
                this.tableData = data
            })
            //总条数
            this.$axios({
                url: `wuJiFour`,
                params: {
                    mingcheng_like: `${this.inputZ}`
                }
            }).then(({ data }) => {
                this.total = data.length
            })
        },
        handleSizeChange(val) {
            this.pageSize = val
            this.Redom()
        },
        //分页
        handleCurrentChange(v) {
            this.currentPage = v
            this.$axios({
                url: `wuJiFour?_page=${v}&_limit=5`,
                params: {
                    mingcheng_like: `${this.inputZ}`
                }

            }).then((data) => {
                this.tableData = data.data

            })
        },

        //添加
        handleAdd() {
            this.$axios.post(`wuJiFour`, {
                mingcheng: this.input,
                shuliang: this.input2,
                bitianxiang: '必填项'
            }).then(() => {
                this.Redom()
            })
        },
        //删除
        Del(row) {
            this.$axios.delete(`/wuJiFour/${row.id}`).then(() => {
                this.currentPage4 = 1
                this.Redom()
            })
        },
        //修改
        Edit(row) {
            this.$store.commit('setid', row.id,)
            this.$store.commit('euJi_page',this.$store.state.wuJi_page)
            this.$router.push(`/home/knowledge/wuJiC/wuJi6/`)
            this.currentPage4 = this.$store.state.wuJi_page
            console.log();
        },
        //查询
        handleQuery() {

            // 执行查询操作，并获取查询结果的总条目数
            //let totalItems = performQueryAndGetTotalItems();
            // 根据每页显示的数量和总条目数计算出总页数
            //let totalPages = Math.ceil(this.total / this.pageSize);

            // 将总页数赋值给pagination组件中的total属性
            // this.total = totalPages;
            //this.currentPage4=1
            this.Redom()
        },
        chongzhi() {
            this.inputZ = ''
            this.currentPage4 = 1
            this.Redom()
        },
    },
    mounted() {
        this.Redom()
    }
}
</script>

<style scoped>
.el-pagination {
    margin-top: 30px;
}
</style>